

/*
*		Global variable define
*/

#pragma once

#include "CxType.h"
#include "CxTime.h"
#include "CxPort/CxSerialPort.h"


BEGIN_NAMESPACE(MSG_SIGN)

class CxGlobalVariable
{
	typedef boost::mutex	_Mutex;
	typedef unsigned char	_Byte;
private:
	static	_Byte			s_temper;
	static	_Byte			s_smoke;
	static	CxSerialPort	*s_globalPort;
	static	CxTime			*s_globalTime;
	static	_Mutex			s_globalmu;
	static	size_t			s_ref;

public:
	CxGlobalVariable()
	{
		++s_ref;
		if(s_globalPort==NULL)
			s_globalPort=new CxSerialPort;
		if(s_globalTime==NULL)
			s_globalTime=new CxTime;
	}
	~CxGlobalVariable()
	{
		--s_ref;
		if(s_ref==0)
		{
			delete s_globalPort;
			delete s_globalTime;
		}
	}
public:

	CxSerialPort		*getPort()
	{
		if(s_globalPort==NULL)
		{
			s_globalPort=new CxSerialPort;
		}
		return s_globalPort;
	}

	_Byte					getTmp()const{return s_temper;}
	_Byte					getSmoke()const{return  s_smoke;}

	CxTime				*getTime()
	{
		if(s_globalTime==NULL)
			s_globalTime=new CxTime;
		return s_globalTime;
	}


};


END_NAMESPACE